package nonogram;

public class SubGroup {
	
	private int start;
	private int end;
	
	public SubGroup(int startVal, int endVal) {
		start = startVal;
		end = endVal;
	}
		
	public int getStart() {
		return start;
	}
	
	public void setStart(int s) {
		start = s;
	}
	
	public int getEnd() {
		return end;
	}
	
	public void setEnd(int e) {
		end = e;
	}
	
	public int getSize() {
		return end - start;
	}
	
	public SubGroup intersect(SubGroup other) {
		if (this.getStart() == -1 || other.getStart() == -1) {
			return new SubGroup(-1, -1);
		}
		
		if (this.getEnd() <= other.getStart() || other.getEnd() <= this.getStart()) {
			return new SubGroup(-1, -1);
		}
		
		int start = Math.max(this.getStart(), other.getStart());
		int end = Math.min(this.getEnd(), other.getEnd());
		
		return new SubGroup(start, end);
	}
	
	@Override
	public String toString() {
		return this.getStart() + ":" + this.getEnd();
	}
}
